home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / libfpvm / WIN32 / ftocstr.c next >
C/C++ Source or Header  |  1997-07-22  |  928b  |  56 lines

  1.  
  2. /* $Id: ftocstr.c,v 1.1 1997/06/27 16:08:08 pvmsrc Exp $ */
  3.  
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include "../../src/bfunc.h"
  7.  
  8. #ifndef min
  9. #define min(i,j) ((i)<(j)?(i):(j))
  10. #endif
  11.  
  12.  
  13. ftocstr(ds, dl, ss, sl)
  14.     char *ds, *ss;      /* dst, src ptrs */
  15.     int dl;             /* dst max len */
  16.     int sl;             /* src len */
  17. {
  18.     char *p;
  19.  
  20.     for (p = ss + sl; --p >= ss && *p == ' '; ) ;
  21.     sl = p - ss + 1;
  22.     dl--;
  23.     ds[0] = 0;
  24.     if (sl > dl)
  25.         return 1;
  26.     strncat(ds, ss, min(sl, dl));
  27.     return 0;
  28. }
  29.  
  30.  
  31. ctofstr(ds, dl, ss)
  32.     char *ds;        /* dest space */
  33.     int dl;            /* max dest length */
  34.     char *ss;        /* src string (0-term) */
  35. {
  36.     int sl = strlen(ss);
  37.  
  38.     if (dl <= sl)
  39.         BCOPY(ss, ds, dl);
  40.  
  41.     else {
  42.         
  43.         if ((ds=malloc(sizeof(char)*sl)) == 0)
  44.             fprintf(stderr,"malloc in ctofstr failed \n");
  45.         memcpy(ds,ss,sl);
  46.         return 0;
  47.  
  48.         dl -= sl;
  49.         ds += sl;
  50.         while (dl-- > 0)
  51.             *ds++ = ' ';
  52.     }
  53.     return 0;
  54. }
  55.  
  56.